<template>
  <el-container class="home-container">

    <el-header class="el-header" height="">
      <h2>物业管理系统</h2>
      <el-dropdown>
        <span class="el-dropdown-link">
          {{ username }} <i class="el-icon-arrow el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <span @click="logout">退出</span>
          </el-dropdown-item>
          <el-dropdown-item>
            <span>个人信息</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>

    <el-container :direction="vertical">

        <el-aside class="el-aside" :width="isCollapse?'64px':'200px'">
            <div class="toggle-button" @click="toggleCollapse">|||</div>
            <el-menu
                :collapse="isCollapse"
                :collapse-transition="false"
                :router="true"
                unique-opened
                background-color="404147"
                text-color="#fff"
                active-text-color="#ffd04b"
                default-active="2"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose">

                <el-submenu index="0">
                  <template slot="title">
                    <i class="el-icon-setting"></i>
                    <span>首页</span>
                  </template>
                  <el-menu-item index="/welcome">
                     <template>
                      <i class="el-icon-location"></i>
                      <span>首页</span>
                     </template> 
                  </el-menu-item>
                </el-submenu>

                <el-submenu index="1">
                  <template slot="title">
                    <i class="el-icon-setting"></i>
                    <span>系统管理</span>
                  </template>
              
                  <el-menu-item index="/user/list">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>用户管理</span>
                    </template>
                  </el-menu-item>
                  
                  <el-menu-item index="/role/list">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>角色管理</span>
                    </template>
                  </el-menu-item>

                  <el-menu-item index="/menu/list">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>菜单管理</span>
                    </template>
                  </el-menu-item>
                </el-submenu>

                <el-submenu index="2">
                  <template slot="title">
                    <i class="el-icon-setting"></i>
                    <span>房屋管理</span>
                  </template>
              
                  <el-menu-item index="2-1">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>楼栋管理</span>
                    </template>
                  </el-menu-item>
                  
                  <el-menu-item index="2-2">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>单元管理</span>
                    </template>
                  </el-menu-item>

                  <el-menu-item index="2-3">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>房屋管理</span>
                    </template>
                  </el-menu-item>
                </el-submenu>
             </el-menu>
        </el-aside>

        <el-main class="el-main"  height="">
          <router-view></router-view>
        </el-main>

    </el-container>
    
  </el-container>
  
</template>

<script>
import { logoutApi ,getInfoApi} from '@/api/login';
export default {
  name: 'Home',

  data() {
    return {
        username:'',
        isCollapse: false
      
    };
  },

  mounted() {
    this.getInfo();
    
  },

  methods: {
    async logout(){
        let res =await logoutApi();
        if(res.code==200){
            this.$router.push("/");
            this.$message(res.msg);
            window.sessionStorage.clear();
        }
    },
    async getInfo(){
        let res =await getInfoApi();
        console.log(res);
        if(res.code==200){
            this.username=res.data.username;
           }else{
            this.$message.error(res.msg);
           }
    },

    toggleCollapse(){
      this.isCollapse=!this.isCollapse;
    },
 
  },
};
</script>

<style lang="less" scoped>
  .home-container{
    height:100%;
    .el-header{
      background-color: #373c41;
      h2{
        color:#ffffff;
        font-size: 21px;
        font-family: '宋体';
        line-height: 60px;
        float: left;
      }
      .el-dropdown{
        float: right;
        margin-right:70px;
        line-height: 60px;
        color: #ffffff;
      }
    }
    .el-aside{
      background-color: #404147;
      
      .toggle-button{
        background-color: #4a5064;
        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
      }
      .el-menu{
        border-right: none;
      }
 
    }
    .el-main{
      background-color:#EAEDF2;
    }
  }

</style>